package com.example.demo.controller.system;

import com.example.demo.model.system.Permission;
import com.example.demo.model.ResponseMessage;
import com.example.demo.service.system.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/permission")
public class PermissionController {
    @Autowired
    private PermissionService service;

    @RequestMapping("save")
    public ResponseMessage save(Permission permission){
        ResponseMessage responseMessage = new ResponseMessage();
        Boolean flag = service.save(permission);
        responseMessage.setFlag(flag);

        return  responseMessage;
    }

    //  根据super_id查询
    @RequestMapping("selectBySuperId")
    public List<Permission> selectBySuperId(Integer super_id){return service.selectBySuperId(super_id);}

    //    查询全部
    @RequestMapping("selectAll")
    public List<Permission> selectAll(){return service.selectAll();}

    //    添加数据
    @RequestMapping("addPermission")
    public Integer addPermission(Permission permission){return service.addPermission(permission);}

    //    删除数据
    @RequestMapping("deleteById")
    public Boolean deleteById(Integer permission_id){return service.deleteById(permission_id)==1;}

    //    更新数据
    @RequestMapping("updateById")
    public Integer updateById(Permission permission){return service.updateById(permission);}

    //    模糊查询
    @RequestMapping("findPermission")
    public List<Permission> findPermission(String title,String url,Integer super_id){return service.findPermission(title,url,super_id);}

}
